package com.lh.music.fragment;


import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.lh.music.R;
import com.lh.music.adapter.VPFTitleAdapter;
import com.lh.music.datamanager.DataManager;
import com.lh.music.fragment.discover.GedanFragment;
import com.lh.music.fragment.discover.GexingFragment;
import com.lh.music.fragment.discover.PaihangFragment;
import com.lh.music.fragment.discover.DiantaiFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class DiscoverFragment extends Fragment {
    private View view;
    private TabLayout tab;
    private ViewPager viewPager;
    private List<Fragment> fragmentList=new ArrayList<>();
    private VPFTitleAdapter pagerAdapter;
    public DiscoverFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        if (view==null) {
            view = inflater.inflate(R.layout.fragment_discover, container, false);
            tab = (TabLayout) view.findViewById(R.id.tab);
            viewPager = (ViewPager) view.findViewById(R.id.viewPager);
            initFragment();
            pagerAdapter = new VPFTitleAdapter(getChildFragmentManager(), fragmentList, DataManager.getDiscoverTabTitle());
            viewPager.setAdapter(pagerAdapter);
            tab.setupWithViewPager(viewPager);
        }
        return  view;
    }

    private void initFragment() {
        GexingFragment gexing=new GexingFragment();
        GedanFragment gedan=new GedanFragment();
        DiantaiFragment zhubo=new DiantaiFragment();
        PaihangFragment paihang=new PaihangFragment();
        fragmentList.add(gexing);
        fragmentList.add(gedan);
        fragmentList.add(zhubo);
        fragmentList.add(paihang);
    }

}
